// Brutal congestion control - fixed bandwidth

use super::CongestionController;
use std::time::Duration;

pub struct BrutalCongestionController {
    target_bandwidth: u64, // bytes per second
    sent_bytes: usize,
    last_reset: Duration,
}

impl BrutalCongestionController {
    pub fn new(target_bandwidth: u64) -> Self {
        Self {
            target_bandwidth,
            sent_bytes: 0,
            last_reset: Duration::ZERO,
        }
    }
}

impl CongestionController for BrutalCongestionController {
    fn on_sent(&mut self, bytes: usize, now: Duration) {
        // Reset counter every second
        if now.as_secs() > self.last_reset.as_secs() {
            self.sent_bytes = 0;
            self.last_reset = now;
        }
        
        self.sent_bytes += bytes;
    }

    fn on_ack(&mut self, _bytes: usize, _rtt: Duration, _now: Duration) {
        // Brutal doesn't care about ACKs
    }

    fn on_loss(&mut self, _bytes: usize, _now: Duration) {
        // Brutal doesn't care about losses
    }

    fn can_send(&self) -> bool {
        // Allow sending if we haven't exceeded bandwidth limit
        (self.sent_bytes as u64) < self.target_bandwidth
    }

    fn bandwidth(&self) -> u64 {
        self.target_bandwidth
    }
}
